/*

HEADER START


harfst_et_al_2023_jepop_regional_candidate_data.do
last modified 20230313 by P. Harfst


Replication Syntax for

Harfst, Philipp; Bol, Damien; Blais, André; Golder, Sona N.; Laslier, Jean-François; Stephenson, Laura; Van Der Straeten, Karine, 2023: "All (Electoral) Politics is Local? Candidate's Regional Roots and Vote Choice", in: Journal of Elections, Public Opinion and Parties, https://doi.org/10.1080/17457289.2023.2189257


HEADER END

*/



set more off
set scheme lean1

*** Load Data
*************

use harfst_et_al_2023_jepop_regional_candidate_data.dta, clear


*************************************
**** ANALYSIS -- Stacked Data Set ***
*************************************


***Variable Labels

label var quest_id "Voter ID"
label var pri_open "Open list vote"
label var regio_cand_vote "Regional candidate vote (0 no, 1 yes)"
label var treat "Ballot paper information (0 no, 1 yes)"
label var cand_gender "Candidate: gender (0 male, 1 female)"
label var cand_academ "Candidate: academic title (0 no, 1 yes)"
label var cand_honor "Candidate: noble title (0 no, 1 yes)"
label var cand_incumbent "Candidate: incumbent (0 no, 1 yes)"
label var cand_pos "Candidate: list position"
label var interest "Voter: interest in politics (0 min, 10 max)"
label var gender_resp "Voter: gender (0 male, 1 female)"
label var know_resp "Voter: political knowledge (0 min, 5 max)"
label var know_max "Voter: political knowledge high (0 no, 1 yes)"
label var east "Voter: East German (0 no, 1 yes)"
label var pos "Positive vote"
label var pos_regio "Positive regional vote"
label var neg "Negative vote"
label var neg_regio "Negative regional vote"




*** Multinominal Logistic Regression with Marginal Effects ***
**************************************************************

***Regio

mlogit cand_points i.regio_cand_vote i.treat cand_gender cand_academ cand_honor cand_incumbent cand_pos interest_resp gender_resp know_resp east i.pri_open, base(2) cluster(quest_id)

est store base


mlogit cand_points i.regio_cand_vote##i.treat cand_gender cand_academ cand_honor cand_incumbent cand_pos interest_resp gender_resp know_resp east i.pri_open, base(2) cluster(quest_id)

est store base_ia


margins regio_cand_vote, at(treat=0) atmeans
margins regio_cand_vote, at(treat=1) atmeans



forvalues o = 1/3 {
	local oname: word `o' of NegativeVote Default PositiveVote
	margins treat, dydx(regio_cand_vote) atmeans post predict(outcome(`o'))
	estimates store `oname'
	quietly estimates restore base_ia
}

coefplot NegativeVote Default PositiveVote, xline(0, lp(dash)) xtitle("Difference in predicted probabilities") ytitle("") ylabel(1 "Ballot info: no" 2 "Ballot info: yes") legend(row(1) position(6) size(small)) xlabel(-.6(.2).6) name(regio, replace)



*** Multinominal Logistic Regression with Marginal Effects -- by Candidate and Voter Characteristics ***
********************************************************************************************************


* CANDIDATE CHARACTERISTICS *
*****************************


***Regio -- by Candidate: incumbent

mlogit cand_points i.regio_cand_vote##i.treat##i.cand_incumbent cand_gender cand_academ cand_honor cand_pos interest gender_resp know_resp east i.pri_open, base(2) cluster(quest_id)

est store incumbent


forvalues o = 1/3 {
	local oname: word `o' of NegativeVote Default PositiveVote
	margins, dydx(regio_cand_vote) at(treat=0 cand_incumbent=0) at(treat=0 cand_incumbent=1) at(treat=1 cand_incumbent=0) at(treat=1 cand_incumbent=1) atmeans post predict(outcome(`o'))
	estimates store `oname'
	quietly estimates restore incumbent
}

coefplot NegativeVote Default PositiveVote, xline(0, lp(dash)) xtitle("Difference in predicted probabilities") ytitle("") ylabel(1 "Info: no, incumbent: no" 2 "Info: no, incumbent: yes" 3 "Info: yes, incumbent: no" 4 "Info: yes, incumbent: yes") legend(row(1) position(6) size(small)) xlabel(-.6(.2).6) name(incumbent, replace)



* VOTER CHARACTERISTICS *
*************************


***Regio -- by Voter Knowledge (Dichotomise Knowledge)

mlogit cand_points i.regio_cand_vote##i.treat##i.know_max cand_gender cand_academ cand_honor cand_incumbent cand_pos interest gender_resp east i.pri_open, base(2) cluster(quest_id)

est store know



forvalues o = 1/3 {
	local oname: word `o' of NegativeVote Default PositiveVote
	quietly margins, dydx(regio_cand_vote) at(treat=0 know_max=0) at(treat=0 know_max=1) at(treat=1 know_max=0) at(treat=1 know_max=1) atmeans post predict(outcome(`o'))
	estimates store `oname'
	quietly estimates restore know
}

coefplot NegativeVote Default PositiveVote, xline(0, lp(dash)) xtitle("Difference in predicted probabilities") ytitle("") ylabel(1 "Info: no, know: min" 2 "Info: no, know: max" 3 "Info: yes, know: min" 4 "Info: yes, know: max") legend(row(1) position(6) size(small)) xlabel(-.6(.2).6) name(know_02, replace)


***Regio -- by Voter East

mlogit cand_points i.regio_cand_vote##i.treat##i.east cand_gender cand_academ cand_honor cand_incumbent cand_pos interest gender_resp know_resp i.pri_open, base(2) cluster(quest_id)

est store east



forvalues o = 1/3 {
	local oname: word `o' of NegativeVote Default PositiveVote
	quietly margins, dydx(regio_cand_vote) at(treat=0 east=0) at(treat=0 east=1) at(treat=1 east=0) at(treat=1 east=1) atmeans post predict(outcome(`o'))
	estimates store `oname'
	quietly estimates restore east
}

coefplot NegativeVote Default PositiveVote, xline(0, lp(dash)) xtitle("Difference in predicted probabilities") ytitle("") ylabel(1 "Info: no, id: low" 2 "Info: no, id: high" 3 "Info: yes, id: low" 4 "Info: yes, id: high") legend(row(1) position(6) size(small)) xlabel(-.6(.2).6) name(east, replace)



******************************
*** TABLES FOR PUBLICATION ***
******************************

***TABLES 1, 2 & 3
******************


tab cand_points regio_cand_vote, col
tab cand_points regio_cand_vote if treat==0, col
tab cand_points regio_cand_vote if treat==1, col


*******************************
* Analyses at the Voter Level *
*******************************

*** ...go to the voter level... *

collapse (sum) neg neg_regio pos pos_regio (first) interest_resp gender_resp know_resp east pri_open number_positive number_negative number_total, by(quest_id)


***Appendix: Use of positive / negative votes by voters' knowledge and interest


gen Negative=neg
gen NegativeRegional=neg_regio
gen Positive=pos
gen PositiveRegional=pos_regio


*Bar Graphs
graph bar (mean) Negative Positive, stack over(know_resp, relabel(1 "Knowledge: min" 6 "Knowledge: max")) nolabel legend(row(1) position(6) size(small)) ytitle("Average number of preference votes") name(bar_know, replace)

graph bar (mean) Positive PositiveRegional, stack over(know_resp, relabel(1 "Knowledge: min" 6 "Knowledge: max")) nolabel legend(row(1) position(6) size(small)) ytitle("Average number of preference votes") ylabel(0(2)8) name(bar_pos, replace)

graph bar (mean) Negative NegativeRegional, stack over(know_resp, relabel(1 "Knowledge: min" 6 "Knowledge: max")) nolabel legend(row(1) position(6) size(small)) ytitle("Average number of preference votes") ylabel(0(2)8) name(bar_neg, replace)


*Regressions knowledge (number of preference votes)
regress number_positive know_resp interest_resp gender_resp east i.pri_open
est sto positive

regress number_negative know_resp interest_resp gender_resp east i.pri_open
est sto negative

regress number_total know_resp interest_resp gender_resp east i.pri_open
est sto total


*Regressions knowledge (positive and negative regional votes)
regress pos know_resp interest_resp gender_resp east i.pri_open
est sto pos

regress pos_regio know_resp interest_resp gender_resp east i.pri_open
est sto pos_reg

regress neg know_resp interest_resp gender_resp east i.pri_open
est sto neg

regress neg_regio know_resp interest_resp gender_resp east i.pri_open
est sto neg_reg


******************************************
*** FIGURES AND TABLES FOR PUBLICATION ***
******************************************


***FIGURES
**********

***FIGURE 1

graph display regio
graph export figure_01.png, replace



***FIGURE 2

graph display east
graph export figure_02.png, replace


***FIGURE 3

graph display know_02
graph export figure_03.png, replace


***FIGURE 4

graph display incumbent
graph export figure_04.png, replace



***APPENDIX
***********


***TABLE A5 MLR Candidate and Voter Characteristics

esttab east know incumbent using "tab_a05.rtf", replace 				///
	se obslast compress b(3) nobaselevels label							///
    star (+ 0.1 * 0.05 ** 0.01 *** 0.001) pr2


***FIGURE A7

graph display bar_know
graph export figure_a07.png, replace


***TABLE A8

esttab positive negative total using "tab_a08.rtf", replace 				///
	se obslast compress b(3) nobaselevels label								///
    star (+ 0.1 * 0.05 ** 0.01 *** 0.001) r2


***FIGURE A9

graph display bar_pos
graph export figure_a09.png, replace


***FIGURE A10

graph display bar_neg
graph export figure_10.png, replace


***TABLE A11

esttab pos pos_reg neg neg_reg using "tab_a11.rtf", replace 				///
	se obslast compress b(3) nobaselevels label								///
    star (+ 0.1 * 0.05 ** 0.01 *** 0.001) r2


***TABLE A14: MLR Base

esttab base base_ia using "tab_a14.rtf", replace 				///
	se obslast compress b(3) nobaselevels label					///
    star (+ 0.1 * 0.05 ** 0.01 *** 0.001) pr2
